﻿<%@ page contentType="text/html; charset=utf-8" language="java" %>
<%@page import="java.util.Iterator;"%>
<%@page import="java.util.Properties;"%>
<%@page import="java.io.IOException;"%>
<%@page import="java.io.FileNotFoundException;"%>
<%@page import="java.io.FileInputStream;"%>
<%@page import="java.io.File;"%>
<%@page import="java.io.InputStream;"%>
<%@page import="java.util.Collections;"%>
<%@page import="java.util.List;"%>
<%@page import="java.util.ArrayList;"%>
<% 
String path = request.getContextPath();
InputStream inputStream;
String optionString = "";
List<String> list = new ArrayList<String>();
		try {
			String strFile = "pattens" + File.separator
					+ "crawl.patten";
			File file = new File(strFile);

			File fileDirs = new File(file.getParent());
			if (!fileDirs.exists()) {
				fileDirs.mkdirs();
			}

			if (!file.exists()) {

				file.createNewFile();
			}
			System.out.println(file.getAbsolutePath());

			inputStream = new FileInputStream(strFile);

			Properties properties = new Properties();

			properties.load(inputStream);
			Iterator iterator = properties.keySet().iterator();
			
			

			while (iterator.hasNext()) {
			String pattenName = (String) iterator.next();
			list.add(pattenName);
		}
		Collections.sort(list);
		optionString = optionString + "<option value= '" + "'>" + "none" + "</option>";
					
		for (int i = 0; i < list.size(); i++) {
			String pattenName = list.get(i);
			String pattenValue = properties.getProperty(pattenName);
			optionString = optionString + "<option value= '" + pattenValue
					+ "'>" + pattenName + "</option>";
		}

		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
%>
<html>
<head>
<script type="text/javascript" src="js/startDate.js"></script>
<script type="text/javascript" src="js/seedList.js"></script>

<title>新建任务</title>
<link href="<%=path%>/css/form.css" rel="stylesheet" type="text/css"/>
<link href="<%=path%>/css/font.css" rel="stylesheet" type="text/css"/>

<script type="text/javascript" language="javascript">
var checknode="random";
function getRadioValue(radioName){
 var obj=document.getElementsByName(radioName);   
        for(var i=0;i<obj.length;i++){   
        if(obj[i].checked){ 
            checknode  =  obj[i].id
            return checknode;   
            }   
        }  
 }
 function checkMatchRadio(){
    var checkval = getRadioValue("nodecheck");
    if( checkval=="oppoint"){
      document.getElementById("match_list_id").style.display = "";
      document.getElementById("match_id").style.display = "none";
    }else{
      document.getElementById("match_id").style.display = "";
      document.getElementById("match_list_id").style.display = "none";
    }
    
 }
 
 function checkFilterRadio(){
    var checkval = getRadioValue("nodecheck");
    if( checkval=="oppoint"){
      document.getElementById("filter_list_id").style.display = "";
      document.getElementById("filter_id").style.display = "none";
    }else{
      document.getElementById("filter_id").style.display = "";
      document.getElementById("filter_list_id").style.display = "none";
    }
    
 }
 
 function adosubmit(){
    var mysel=document.getElementById("freddnodes");    
    var txt=mysel.options[mysel.options.selectedIndex].text;                                                                     //获取下拉列表框显示的文本 
    
    document.forms[0].action="./setnodecheckval.jsp?checknode="+checknode+"&checkval="+txt;
    document.forms[0].submit();
 }
 

 
  
  /**
  * 添加需要匹配的正则
  */
  function addMatchPatten(){
  
  //获取隐藏框的句柄
  var hiddenMatch = document.getElementById("hiddenMatch_id");
  //先清空隐藏框中的字符
  hiddenMatch.value = "";
  
  var checkval = getRadioValue("nodecheck");
   var oOption = document.createElement("option");
    if( checkval=="oppoint"){
     oOption.text = document.getElementById("match_list_id").value;
         oOption.value = document.getElementById("match_list_id").value;
         document.all.match_list_all.add(oOption);
    }else{
      oOption.text = document.getElementById("match_id").value;
         oOption.value = document.getElementById("match_id").value;
         document.all.match_list_all.add(oOption);
         document.all.match_id.value = "";
    }
    
    //循环遍历列表 将所有内容加入到隐藏的输入框中
     var obj = document.getElementById("match_list_all_id").options;
         for(var i=0;i<obj.length;i++)
         {
           hiddenMatch.value = obj.options[i].value+","+hiddenMatch.value;
         }
         
         alert(hiddenMatch.value);
    
 }
 
   /**
  * 删除需要匹配的正则
  */
  function delMatchPatten(){
  //获取隐藏框的句柄
  var hiddenMatch = document.getElementById("hiddenMatch_id");
  //先清空隐藏框中的字符
  hiddenMatch.value = "";
  
  //删除列表中的内容
  var oSelect = document.all.match_list_all;
     for(var i=0; i<oSelect.options.length; i++)
     {
         if(i>=0 && i<=oSelect.options.length-1 && oSelect.options[i].selected)
         {
             oSelect.options[i] = null;
             i --;
         }
     }
     
     //循环遍历列表 将所有内容加入到隐藏的输入框中
     var obj = document.getElementById("match_list_all_id").options;
         for(var i=0;i<obj.length;i++)
         {
           hiddenMatch.value = obj.options[i].value+","+hiddenMatch.value;
         }
         
         alert(hiddenMatch.value); 
       
     
     
  }
 
  /**
  * 添加需要过滤的正则
  */
  function addFilterPatten(){
  //获取隐藏框的句柄
  var hiddenFilter = document.getElementById("hiddenFilter_id");
  //先清空隐藏框中的字符
  hiddenFilter.value = "";
  
  var checkval = getRadioValue("nodecheck");
      var oOption = document.createElement("option");
    if( checkval=="oppoint"){
     oOption.text = document.getElementById("filter_list_id").value;
         oOption.value = document.getElementById("filter_list_id").value;
         document.all.filter_list_all.add(oOption);
    }else{
      oOption.text = document.getElementById("filter_id").value;
         oOption.value = document.getElementById("filter_id").value;
         document.all.filter_list_all.add(oOption);
         document.all.filter_id.value = "";
    } 
    
      //循环遍历列表 将所有内容加入到隐藏的输入框中
     var obj = document.getElementById("filter_list_all_id").options;
         for(var i=0;i<obj.length;i++)
         {
           hiddenFilter.value = obj.options[i].value+","+hiddenFilter.value;
         }
         
         alert(hiddenFilter.value);
        
 }
 
 /**
  * 删除需要过滤的正则
  */
  function delFilterPatten(){
  //获取隐藏框的句柄
  var hiddenFilter = document.getElementById("hiddenFilter_id");
  //先清空隐藏框中的字符
  hiddenFilter.value = "";
  
  //删除列表中的内容
  var oSelect = document.all.filter_list_all;
     for(var i=0; i<oSelect.options.length; i++)
     {
         if(i>=0 && i<=oSelect.options.length-1 && oSelect.options[i].selected)
         {
             oSelect.options[i] = null;
             i --;
         }
     }
     
      //循环遍历列表 将所有内容加入到隐藏的输入框中
     var obj = document.getElementById("filter_list_all_id").options;
         for(var i=0;i<obj.length;i++)
         {
           hiddenFilter.value = obj.options[i].value+","+hiddenFilter.value;
         }
         
         alert(hiddenFilter.value);
  
  
  
  }
 
 

/**
  * 删除选定项目
  *
  * oSelect: 源列表框对象 
  */
 function deleteSelectItem(oSelect)
 {
     for(var i=0; i<oSelect.options.length; i++)
     {
         if(i>=0 && i<=oSelect.options.length-1 && oSelect.options[i].selected)
         {
             oSelect.options[i] = null;
             i --;
         }
     }
 }
 
   </script>

</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3">
	<!--Start top-->
	<jsp:include page="/page/top.jsp" /></td>
  </tr>
  <tr>
    <td width="194" valign="top">	<!--Start left-->
        <jsp:include page="/page/left_menu_admin.jsp" />  
    <!--End left--></td>
    <td width="20">&nbsp;</td>
    <td width="799" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="39" class="titletop" style="border-bottom:1px dotted #ccc;" ></td>
      </tr>
    </table>
      <br/> 
          <h3>新建任务 </h3>
      <br/>
    <table width="100%">
     <tr>
      
			<form name="form1" method="post" action="newtaskAction.jsp">
			<tr>
			<p>任务名称:<input type="text" name="name"></p>
			
			<p>抓取深度:
			<input type="text" name="deep"  
			value="0" 
			onkeydown="value=value.replace(/[^\d]/, '')" 
			onkeyup="value=value.replace(/[^\d]/, '')"
			> </p></tr>
			
			<DIV style="background-color:#CCCCCC; padding:5px">
       
   </div>
			
			
			<p>起始种子页面:<input type="text" name="seed" id="seed_id" ></p>
			
			<p><input type="hidden" name="hiddenSeeds" id="hiddenSeeds_id"></p>
			
			<tr>当前已选择的种子页</tr>
   <INPUT style="border:1px solid black " type="button" value="添加" onClick="addSeed()">
   <INPUT style="border:1px solid black " type="button" value="删除" onClick="delSeed()">
   <SELECT name="seed_list" size="5" id="seed_list_id" multiple style="width:100px; ">

   </SELECT>
   <br><br>

   <DIV style="background-color:#CCCCCC; padding:5px">
       
   </div>
   
   
			
			<tr>请选择需要匹配的正则</tr>
			<p><input type="hidden" name="hiddenMatch" id="hiddenMatch_id"></p>
			  <tr>
               
                   <input id="random" type="radio" name="nodecheck" checked="checked" onClick="checkMatchRadio();" />手动输入
                   <input type="text" name="match" id="match_id" style="display:none">
             
              </tr>
              
              <tr>
               <label for="radiob" id="radioblab">
                    <input id="oppoint" type="radio" name="nodecheck"  onClick="checkMatchRadio();" />从正则库中选择
                 <select name="match_list"  id="match_list_id" style="display:none;"> 
                 <%= optionString %>
				</select></label>
			
              </tr>
             &nbsp;
   <tr>当前已选择需要匹配的正则</tr>
   <INPUT style="border:1px solid black " type="button" value="添加" onClick="addMatchPatten()">
   <INPUT style="border:1px solid black " type="button" value="删除" onClick="delMatchPatten()">
   <SELECT name="match_list_all" size="5" id="match_list_all_id" multiple style="width:100px; ">

   </SELECT>
   <br><br>

   <DIV style="background-color:#CCCCCC; padding:5px">
       
   </div>
   
              
              &nbsp;
              <tr>请选择需要过滤的正则</tr>
              <p><input type="hidden" name="hiddenFilter" id="hiddenFilter_id"></p>
			  <tr>
              
                   <input id="random" type="radio" name="nodecheck" checked="checked" onClick="checkFilterRadio();" />手动输入
                   <input type="text" name="filter" id="filter_id" style="display:none">
             
              </tr>
              
              <tr>
              <label for="radiob" id="radioblab">
                    <input id="oppoint" type="radio" name="nodecheck"  onClick="checkFilterRadio();" />从正则库中选择
                 <select name="filter_list"  id="filter_list_id" style="display:none;"> 
                 <%= optionString %>
				</select></label>
				
              </tr>
			&nbsp;
			
			<tr>当前已选择需要过滤的正则</tr>
   <INPUT style="border:1px solid black " type="button" value="添加" onClick="addFilterPatten()">
   <INPUT style="border:1px solid black " type="button" value="删除" onClick="delFilterPatten()">
   <SELECT name="filter_list_all" size="5" id="filter_list_all_id" multiple style="width:100px; ">

   </SELECT>
   <br><br>

   <DIV style="background-color:#CCCCCC; padding:5px">
       
   </div>
   
  &nbsp;
			
			
			
			
		
			<p>连接超时时间:
			<input type="text" name="connectiontimeout"  
			value="2000" 
			onkeydown="value=value.replace(/[^\d]/, '')" 
			onkeyup="value=value.replace(/[^\d]/, '')"
			>		
			</p>
			
			
			<p>流读取超时时间:
			<input type="text" name="sockettimeout"  
			value="20000" 
			onkeydown="value=value.replace(/[^\d]/, '')" 
			onkeyup="value=value.replace(/[^\d]/, '')"
			>
			</p>
			
			<p>设定启动时间:
            <input type="text" name="textfield"   onFocus="CalendarWebControl.show(this,true,this.value);"> 
            </p>
           
			<p>运行周期(单位：天):
			<input type="text" name="interval"
			value="360" 
			onkeydown="value=value.replace(/[^\d]/, '')" 
			onkeyup="value=value.replace(/[^\d]/, '')"
			>
			</p>
			
			<p>启动节点数:
			<input type="text" name="nodeCount"
			value="-1" 
			onkeydown="value=value.replace(/[^\d]/, '')" 
			onkeyup="value=value.replace(/[^\d]/, '')"
			>
			</p>
			
			
			<p>下载到本地的文件保存路径:<input type="text" name="filepath" value="Crawler/task/"></p>
			
			
			<p>当节点数不够时是否运行:
			<select name="scalable">
			<option value="YES">运行</option>
			<option value="NO">等待</option>
			</select>
			</p>
			
			
			<p>是否启动监控功能:
			<select name="startmonitor">
			<option value="NO">关闭</option>
			<option value="YES">启动</option>
			</select>
			</p>
			<p>
			<input type="Submit" value="提交">
			<input type="Reset" value="重置">
			</p>
		
			</form>    
        </td>
	  </tr>	  
	 </table>
    </td>
  </tr>
</table>
</body>
</html>